package com.haruhinav.config;

import com.haruhinav.Utils.Constants;
import com.haruhinav.interecptors.AdminInterceptor;
import com.haruhinav.interecptors.JWTInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;


@Configuration
public class InterceptorConfig implements WebMvcConfigurer {

    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        //获取文件的真实路径
        String path = System.getProperty("user.dir")+ Constants.UPLOAD_FILE_RELATIVE_URL;
        //  String path1 = System.getProperty("user.dir")+"\\src\\main\\resources\\static\\static\\";

        registry.addResourceHandler("/upload/**").addResourceLocations("file:"+path);


    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {

        registry.addInterceptor(new JWTInterceptor())
                .addPathPatterns("/**/a/**")
                .excludePathPatterns("/**/e/**");

        registry.addInterceptor(new AdminInterceptor())
                .addPathPatterns("/**/y/**")//拦截
                .excludePathPatterns("/**/x/**");//放行

    }

}
